<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="../../css/font.css">
    <link rel="stylesheet" href="../../css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="../../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../js/xadmin.js"></script>
    <script type="text/javascript" src="../../js/vue.min.js"></script>
    <script type="text/javascript" src="../../js/vue-resource.min.js"></script>

    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div id="product-detail" class="x-body">
    <form class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span> 商品名称</label>
            <div class="layui-input-block">
                <input type="text" id="name" name="name" required v-model="product.name" lay-verify="required"
                       placeholder="商品名称" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span> 商品描述</label>
            <div class="layui-input-block">
                <input type="text" id="description" required v-model="product.description" name="description" required
                       lay-verify="required" placeholder="商品描述" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span> 详情URL</label>
            <div class="layui-input-block">
                <input type="text" id="detailUrl" name="detailUrl" required v-model="product.detailUrl"
                       lay-verify="required" placeholder="详情" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span> 类目</label>
            <div class="layui-input-block">
                <select id="categoryId" lay-verify="">
                    <option value="">请选择一个类目</option>
                    <option value="1">奶粉</option>
                </select>
            </div>
        </div>

        <div id="itemsArea">
            <table class="layui-table">
                <thead>
                <tr>
                    <th>规格</th>
                    <th>成本</th>
                    <th>售价</th>
                    <th>库存</th>
                    <th>库存警告数量</th>
                </tr>
                </thead>
                <tbody>

                <tr v-for="item in product.items">
                    <td>
                        <li v-for="standard in item.standard">
                                {{ standard.attribute.value }}
                        </li>
                    </td>
                    <td>{{ item.costPrice }}</td>
                    <td>{{ item.costPrice }}</td>
                    <td>
                        {{ item.inventory.amount }}
                    </td>
                    <td>
                        {{ item.inventory.warnAmount }}
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </form>
</div>
<script>
    Vue.use(VueResource);
    var product = new Vue({
        el: '#product-detail',
        data: {
            product: {
                "objectId": layui.data("product").objectId
            },
            items: null,
        },
        ready: function() {

        },
        methods: {
            getProduct: function () {
                this.$http.get("http://localhost:8181/api/product/"+this.product.objectId)
                    .then((response) => {
                        this.product = response.data;
                    }).catch(function (response) {
                    console.log(response)
                });
            },

        }
    });
    product.getProduct();
    layui.use(['form', 'layer', 'table'], function () {

    });


</script>
</body>

</html>